home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Tools&Utilities / CDIconKiller 1.3.3 / sources / CDIconKiller.c < prev    next >
C/C++ Source or Header  |  1995-06-03  |  6KB  |  310 lines

  1. #ifndef __Assembler__
  2. #include    <Assembler.h>
  3. #endif
  4. /*
  5. ; CDIconKiller © 1994, 1995 Quinn & Peter N Lewis, Fabrizio Oddone
  6. ; Version 1.0 written in 4 hours from 02:00 to 05:30 18/June/94
  7.  
  8. bug fixes, CD driver string in resource (suggested by Quinn),
  9. asm tweaks etc. (version 1.1 thru 1.3) by Fabrizio Oddone
  10.  
  11. ; Patches GetCatInfo, tests for Custom Icon attribute on
  12. ; CD-ROM files/folders, and clears it.
  13.  
  14. ; Detailed description:
  15.  
  16. ; Init time:
  17. ;   load the resource containing the driver strings
  18. ;   Patch GetCatInfo
  19.  
  20. ; GetCatInfo Patch:
  21. ;   Test for GetCatInfo selector on HFSDispatch, do nothing otherwise
  22. ;   Call thru
  23. ;   Return immediately on error or async call
  24. ;   Return immediately unless Custom Icon bit set
  25. ;   Walk the volume queue looking for the vrefnum of the GetCatInfo
  26. ;   If we don't find it, we leave
  27. ;   If the command key is down, we leave
  28. ;   We determine whether the driver refnum is known (yes/no custom icons)
  29. ;   If "no", then clear the custom icon bit
  30. ;   If "yes", then leave
  31. ;   If the driver refnum is NOT known, we scan the driver queue and update our lists
  32.  
  33.     include    'sysequ.a'
  34.     include    'fsequ.a'
  35.     include    'traps.a'
  36.  
  37. ; procedure ShowIcon (id: integer; delta_x: integer);
  38.     import    ShowIcon
  39. */
  40. //main    proc    export
  41. extern pascal void ShowIcon(short iconID, short pixels);
  42.  
  43. #define    patchSize    (526)    // because of CodeWarrior asm limitations
  44. #define    HFSDispatchTrapNum    0x60
  45.  
  46. asm void main(void)
  47. {
  48.     subq.w    #4,sp
  49.     move.l    #'STR#',-(SP)
  50.     move.w    #128,-(sp)
  51.     _Get1Resource
  52.     move.l    (sp)+,d0
  53.     beq.s    bad
  54.     lea    stringH,a0
  55.     move.l    d0,(a0)    // remember string handle
  56.     move.l    d0,-(sp)
  57.     _DetachResource
  58.  
  59.     moveq    #HFSDispatchTrapNum,d0    // patch HFSDispatch
  60.     _GetOSTrapAddress
  61.     lea    oldHFSDispatch,a1
  62.     move.l    a0,(a1)
  63.  
  64. //    move.l    #(EndHFSDispatch-OurHFSDispatch),d0
  65.     move.l    #patchSize,d0
  66.     _NewPtrSys
  67.     bne.s    baddisposepref
  68.     
  69.     movea.l    a0,a1
  70.     lea    OurHFSDispatch,a0
  71.     move.l    #patchSize,d0
  72. //    move.l    #(EndHFSDispatch-OurHFSDispatch),d0
  73.     _BlockMove
  74.  
  75.     moveq    #HFSDispatchTrapNum,d0
  76.     movea.l    a1,a0
  77.     _SetOSTrapAddress    
  78.  
  79.     MOVE.L    #0xffff0080,-(SP)
  80.     JSR    ShowIcon
  81. bad:
  82.     rts
  83.  
  84. baddisposepref:
  85.     movea.l    stringH,a0
  86.     _DisposHandle
  87.     rts
  88.  
  89.  
  90. OurHFSDispatch:
  91.     cmp.w    #9,d0    // Test for GetCatInfo selector
  92.     bne.s    dontdoit
  93.     pea    continued
  94. dontdoit:
  95.     move.l    oldHFSDispatch,-(sp)    // Call thru
  96.     rts
  97.  
  98. continued:
  99.     tst.w    struct (DirInfo.ioResult)(a0)
  100.     bne.s    fin    // give up on error or async
  101.     
  102.     btst    #2,struct (DirInfo.ioDrUsrWds.frFlags)(a0)
  103.     beq.s    fin    // give up unless custom icon
  104.     
  105.     movem.l    a1/d1,-(sp)
  106.     
  107.     MOVE.L    A0,-(SP)
  108.     LEA    -sizeof(EventRecord)(SP),SP
  109.     MOVEA.L    SP,A0
  110.     MOVEQ    #0,D0
  111.     _OSEventAvail
  112.     BTST    #0,struct (EventRecord.modifiers)(A0)    //cmdKey
  113.     LEA    sizeof(EventRecord)(SP),SP
  114.     MOVEA.L    (SP)+,A0
  115.     bne.s    leave
  116.  
  117.     movea.l    0x358,a1    // first volume control block LMGetVCBQHdr()+2
  118.     move.w    struct (DirInfo.ioVRefNum)(a0),d1
  119. lop:
  120.     cmp.w    struct (VCB.vcbVRefNum)(a1),d1
  121.     bne.s    cont
  122.  
  123.     move.w    struct (VCB.vcbDRefNum)(a1),d1
  124. //    _Debugger
  125.     bsr    finddriverdontwantcustomicons
  126.     bne.s    clearcustombit
  127.     bsr    finddriverwantcustomicons
  128.     bne.s    leave
  129.     bsr.s    findDriverbyName
  130.     bra.s    leave
  131. clearcustombit:
  132.     bclr    #2,struct (DirInfo.ioDrUsrWds.frFlags)(a0)    // clear custom icon
  133.     bra    leave
  134. cont:
  135.     movea.l    (a1),a1    // next volume control block
  136.     move.l    a1,d0
  137.     bne.s    lop
  138.  
  139. leave:
  140.     movem.l    (sp)+,a1/d1
  141.     moveq    #0,d0
  142.     
  143. fin:
  144.     tst.w    d0
  145. notstfin:
  146.     rts
  147.  
  148. finddriverdontwantcustomicons:
  149.     move.l    a0,-(sp)
  150.     lea    lastskipthesedrivers,a0
  151.     move.w    d1,(a0)
  152.     lea    skipthesedrivers,a0
  153. loopfinddontwant:
  154.     cmp.w    (A0)+,D1
  155.     bne.s    loopfinddontwant
  156.     pea    lastskipthesedrivers+2
  157.     cmpa.l    (sp)+,A0
  158.     movea.l    (sp)+,a0
  159.     rts
  160.  
  161. finddriverwantcustomicons:
  162.     move.l    a0,-(sp)
  163.     lea    lastotherdrivers,a0
  164.     move.w    D1,(a0)
  165.     lea    otherdrivers,a0
  166. loopfindwant:
  167.     cmp.w    (A0)+,D1
  168.     bne.s    loopfindwant
  169.     pea    lastotherdrivers+2
  170.     cmpa.l    (sp)+,A0
  171.     movea.l    (sp)+,a0
  172.     rts
  173.  
  174. findDriverbyName:
  175.     movem.l    a0-a4/a6/d1/d3-d5,-(sp)
  176.     moveq    #0,d5
  177.     lea    nextfreedontwant,a3
  178.     tst.l    (a3)
  179.     bne.s    alreadyinitednfdw
  180.     st    d5
  181.     pea    skipthesedrivers
  182.     move.l    (sp)+,(a3)
  183. alreadyinitednfdw:
  184.     movea.l    (a3),a0
  185.     pea    lastskipthesedrivers
  186.     cmpa.l    (sp)+,a0
  187.     beq.s    plainexit
  188.     lea    nextfreewant,a4
  189.     tst.l    (a4)
  190.     bne.s    alreadyinitednfw
  191.     pea    otherdrivers
  192.     move.l    (sp)+,(a4)
  193. alreadyinitednfw:
  194.     movea.l    (a4),a0
  195.     pea    lastotherdrivers
  196.     cmpa.l    (sp)+,a0
  197.     beq.s    plainexit
  198.  
  199.  
  200.     movea.l    0x11C,a2    // LMGetUTableBase()
  201.     move.w    0x1d2,d3    // LMGetUnitTableEntryCount()
  202. loop:
  203.     move.l    (a2)+,d0
  204.     beq.s    endloop
  205.     movea.l    d0,a1
  206.  
  207. // a1 = curDCtlHndl
  208.  
  209.     movea.l    (a1),a1
  210.     move.l    /*struct (DCtlEntry.dCtlDriver)*/(a1),d0
  211.     beq.s    endloop
  212.     movea.l    d0,a0
  213.     btst    #6,(struct (DCtlEntry.dCtlFlags)+1)(a1)    // test for RAMDriver
  214.     beq.s    notram
  215.     move.l    (a0),d0
  216.     beq.s    endloop
  217.     movea.l    d0,a0
  218. notram:
  219.     move.w    d3,d4
  220.     sub.w    0x1d2,d4    // calc driver refnum -(unit num+1) LMGetUnitTableEntryCount()
  221.     subq.w    #1,d4
  222.     tst.b    d5
  223.     bne.s    firsttime
  224.     move.w    d4,d1
  225.     bsr    finddriverdontwantcustomicons
  226.     bne.s    endloop
  227.     bsr    finddriverwantcustomicons
  228.     bne.s    endloop
  229. firsttime:
  230.     lea    struct (DRVRHeader.drvrName)(a0),a0
  231.     moveq    #0,d2
  232.     move.b    (a0)+,d2
  233.     swap    d2
  234.     bsr    cmpallstrings
  235.     bne.s    endloopsavedriver
  236.     movea.l    a3,a1
  237.     bra.s    commonpart
  238. endloopsavedriver:
  239.     movea.l    a4,a1
  240. commonpart:
  241.     movea.l    (a1),a0
  242.     move.w    d4,(a0)+    // remember driver refnum
  243.     move.l    a0,(a1)
  244. endloop:
  245.     subq.w    #1,d3
  246.     bne    loop
  247. plainexit:
  248.     movem.l    (sp)+,a0-a4/a6/d1/d3-d5
  249.     rts
  250.  
  251. // input: a0 string, d2 (already in hi word) length
  252. // output: sets the flags
  253. // registers are saved&restored by the calling routine
  254. cmpallstrings:
  255.     movea.l    stringH,a6
  256.     movea.l    (a6),a6
  257.     move.w    (a6)+,d1
  258.     andi    #0xB,CCR
  259.     bra.s    thedbcc
  260. cmploop:
  261.     move.l    d2,d0
  262.     move.b    (a6)+,d0
  263.     movea.l    a6,a1
  264.     adda.w    d0,a6
  265.     _CmpString
  266. thedbcc:
  267.     dbeq    d1,cmploop
  268. cmpexit:
  269.     rts
  270.  
  271. skipthesedrivers:
  272.     ds.w    15
  273. lastskipthesedrivers:
  274.     dc.w    -1
  275. otherdrivers:
  276.     ds.w    63
  277. lastotherdrivers:
  278.     dc.w    -1
  279. nextfreedontwant:
  280.     dc.l    0
  281. nextfreewant:
  282.     dc.l    0
  283. stringH:
  284.     dc.l    0
  285. oldHFSDispatch:
  286.     dc.l    0xffffffff
  287.  
  288. EndHFSDispatch:
  289.  
  290.     
  291.  
  292. //    string    pascal
  293.  
  294. }
  295. //    endp
  296.     
  297. //    end
  298.     
  299. /*
  300. asm -wb "{active}"
  301. (evaluate "{active}" =~ "/(?*:)®1(?*)/" )> dev:null
  302. (evaluate "{active}" =~ "/(?*)®2.a/" )> dev:null
  303. link -rt INIT=128 -ra =ressysheap,reslocked -t INIT -c CDik -o "{®2}" "{active}.o" "{®1}ShowIcon.o"
  304. setfile -a B "{®2}"
  305.  
  306.  
  307.  
  308. dumpobj "{®1}SHOWICON.o"
  309. */
  310.